import { Column, Entity, Index, PrimaryGeneratedColumn } from "typeorm";

@Index("ix_order_no", ["orderNo"], {})
@Index(
  "ix_order_user_address_asset_address_asset_type",
  ["userAddress", "assetAddress", "assetType"],
  {}
)
@Entity("tb_order", { schema: "db_test" })
export class TbOrder {
  @PrimaryGeneratedColumn({ type: "int", name: "id", unsigned: true })
  id: number;

  @Column("varchar", {
    name: "order_no",
    comment: "订单号",
    length: 50,
    default: () => "''",
  })
  orderNo: string;

  @Column("int", {
    name: "user_id",
    comment: "用户ID",
    unsigned: true,
    default: () => "'0'",
  })
  userId: number;

  @Column("varchar", {
    name: "user_address",
    comment: "买家地址",
    length: 50,
    default: () => "''",
  })
  userAddress: string;

  @Column("varchar", {
    name: "seller_address",
    comment: "卖家地址",
    length: 50,
    default: () => "''",
  })
  sellerAddress: string;

  @Column("varchar", {
    name: "asset_address",
    comment: "资产合约地址",
    length: 50,
    default: () => "''",
  })
  assetAddress: string;

  @Column("smallint", {
    name: "asset_type",
    comment: "资产类型（1-ERC721, 2-ERC1155, 3-ERC20）",
    unsigned: true,
    default: () => "'0'",
  })
  assetType: number;

  @Column("int", {
    name: "token_id",
    comment: "资产tokenId",
    unsigned: true,
    default: () => "'0'",
  })
  tokenId: number;

  @Column("int", {
    name: "amount",
    comment: "购买数量",
    unsigned: true,
    default: () => "'0'",
  })
  amount: number;

  @Column("decimal", {
    name: "pay_amount",
    comment: "支付金额",
    unsigned: true,
    precision: 30,
    scale: 4,
    default: () => "'0.0000'",
  })
  payAmount: string;

  @Column("timestamp", {
    name: "created_at",
    comment: "创建时间",
    default: () => "'0000-00-00 00:00:00'",
  })
  createdAt: Date;

  @Column("timestamp", {
    name: "updated_at",
    comment: "更新时间",
    default: () => "'0000-00-00 00:00:00'",
  })
  updatedAt: Date;

  @Column("tinyint", {
    name: "is_deleted",
    comment: "是否删除(1-是)",
    unsigned: true,
    default: () => "'0'",
  })
  isDeleted: number;
}
